<?php

namespace App\Models\Contract;

use App\Models\BaseModel;

class ContractModel extends BaseModel
{
    /**
     * 与模型关联的数据表。
     *
     * @var string
     */
    protected $table = 'contract';
    /**
     * 与表关联的主键
     *
     * @var string
     */
    protected $primaryKey = 'id';
    /**
     * 执行模型是否自动维护时间戳。
     *
     * @var bool
     */
    public $timestamps = true;

    /**
     * 可以被批量赋值的属性。
     *
     * @var array
     */
    protected $fillable = array(
        "users_id", "title", "number", "a_name", "b_name", "a_nick", "b_nick",
        "status", "created_at", "updated_at", "deposit_at", "deposit_pic", "area",
        "start_at", "over_at", "remark", "a_phone", "b_phone", "pdf",
        "leader", "leader_phone", "deposit", "channel_code", "contact_code", "channel_qr",
        "introduce", "job_mobile", "job_name"
    );
//    禁止修改字段
    protected $guarded = ['users_id', "created_at", "updated_at"];
    /**
     * 查询数据需要过滤掉的属性。
     *
     * @var array
     */
    protected $hidden = array(
        'updated_at'
    );
    /**
     * 应进行类型转换的属性
     *
     * @var array
     */
    protected $casts = [
        'pics' => 'array',
    ];

    /**
     * 建表语句
     */
    protected function buildTable($name = '')
    {
        return '';
    }

    /**
     * 插入新的字段
     */
    protected function bulidField()
    {
        return [];
    }

    public function getStatusList()
    {
        return config('card.contractStatus');
    }

    public function getStatusDesc($key)
    {
        $allStatus = $this->getStatusList();
        return !empty($allStatus[$key]) ? $allStatus[$key] : '未知';
    }

    public function users()
    {
        return $this->hasOne('App\Models\Admin\AdminUsers', 'id', 'users_id');
    }
}
